package com.tssup.fesco.service.impl;

import com.tssup.fesco.common.constants.ReturnCodeConstants;
import com.tssup.fesco.common.enums.YesNo;
import com.tssup.fesco.common.enums.YesNoBoolean;
import com.tssup.fesco.common.exeception.RetException;
import com.tssup.fesco.common.constants.OfcConstants;
import com.tssup.fesco.common.enumeration.*;
import com.tssup.fesco.service.*;
import com.tssup.fesco.ofc.vo.AddStockParamVo;
import com.tssup.fesco.ofc.vo.OperationPointParameter;
import com.tssup.fesco.sales.ofc.persistent.mapper.OfcIOrderInfoMapper;
import com.tssup.fesco.sales.ofc.persistent.mapper.OfcIOrderRelaMapper;
import com.tssup.fesco.sales.ofc.persistent.pojo.OfcIOrderInfo;
import com.tssup.fesco.sales.ofc.persistent.pojo.OfcIOrderRela;
import com.tssup.fesco.sales.order.persistent.mapper.*;
import com.tssup.fesco.sales.order.persistent.pojo.*;
import com.tssup.fesco.sales.rule.persistent.mapper.IInterfaceMapper;
import com.tssup.fesco.sales.user.persistent.mapper.IInvoiceLogisticsMapper;
import com.tssup.fesco.sales.user.persistent.mapper.IInvoiceMapper;
import com.tssup.fesco.sales.user.persistent.pojo.IInvoice;
import com.tssup.fesco.sales.user.persistent.pojo.IInvoiceLogistics;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * Created by haomin on 2017/4/6.
 */
@Service
public class B2cServiceImpl implements B2cService {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    private static String ORDER_ENTRANCE_ID = "b2c";

    @Autowired
    private IOrderMapper orderMapper;

    @Autowired
    private IOrderLogisticsMapper orderLogisticsMapper;

    @Autowired
    private IInvoiceMapper invoiceMapper;

    @Autowired
    private IInvoiceLogisticsMapper invoiceLogisticsMapper;

    @Autowired
    private OfcIOrderInfoMapper ofcIOrderInfoMapper;

    @Autowired
    private OfcIOrderRelaMapper ofcIOrderRelaMapper;

    @Autowired
    private IOrderDetailMapper orderDetailMapper;

    @Autowired
    private IOrderPayMapper orderPayMapper;

    @Autowired
    private IOrderRemarkMapper orderRemarkMapper;

    @Autowired
    private OrderStatusService orderStatusService;

    @Autowired
    private StockService stockService;

    @Autowired
    private OfcOrderLogService orderLogService;

    @Autowired
    private UserPointService userPointService;

    /**
     * 计算是否需要同步修改父订单的状态
     * @param orderCode
     * @return
     */
    @Transactional
    public void decideAndChangeParentStatus (String orderCode){
        List<OfcIOrderRela> orderRelas = Optional.ofNullable(ofcIOrderRelaMapper.selectByParentOrder(orderCode))
                .orElse(new ArrayList<OfcIOrderRela>());
        List<OfcIOrderInfo> ofcIOrderInfos = new ArrayList<OfcIOrderInfo>();
        orderRelas.forEach(orderRela -> {
            OfcIOrderInfo ofcIOrderInfo = ofcIOrderInfoMapper.selectByOrderId(orderRela.getOrderId());
            if(null != ofcIOrderInfo){
                ofcIOrderInfos.add(ofcIOrderInfo);
            }
        });
        int ofcOperNum = ofcIOrderInfos.size();
        //待发货的订单数
        int ofcWaitSendNum = 0;
        //已发货的订单数
        int ofcSendNum = 0;
        //已收货的订单数
        int ofcReceiveNum = 0;
        //已取消的订单数
        int ofcCancleNum = 0;
        //已拒收的订单数
        int ofcRejectNum = 0;
        for ( OfcIOrderInfo ofcIOrderInfo : ofcIOrderInfos ) {
            if( OfcOrderStatus.WAIT_SHIPPING.getValue().equals(ofcIOrderInfo.getOrderStatus())){
                ofcWaitSendNum ++;
            }
            if(OfcOrderStatus.SHIPPING.getValue().equals(ofcIOrderInfo.getOrderStatus())){
                ofcSendNum ++;
            }
            if(OfcOrderStatus.SIGN_IN.getValue().equals(ofcIOrderInfo.getOrderStatus())){
                ofcReceiveNum ++;
            }
            if(OfcOrderStatus.CANCEL.getValue().equals(ofcIOrderInfo.getOrderStatus())){
                ofcCancleNum ++;
            }
            if(OfcOrderStatus.REFUND.getValue().equals(ofcIOrderInfo.getOrderStatus())){
                ofcRejectNum ++;
            }
        }

        if(ofcWaitSendNum>0 && (ofcWaitSendNum==ofcOperNum || (ofcWaitSendNum+ofcCancleNum)==ofcOperNum ||
                (ofcWaitSendNum+ofcRejectNum)==ofcOperNum || (ofcReceiveNum+ofcCancleNum+ofcWaitSendNum)==ofcOperNum)){
            //如果所有的都是待发货或除待发货的都是取消或拒收的，那么是待发货
            saveOrderStatus2WaitShipping(orderCode);
        }
        if(ofcSendNum>0 && (ofcSendNum==ofcOperNum || (ofcSendNum+ofcCancleNum)==ofcOperNum ||
                (ofcSendNum+ofcRejectNum)==ofcOperNum || (ofcReceiveNum+ofcCancleNum+ofcSendNum)==ofcOperNum)){
            //如果已经有一条是发货，那么是已发货
            saveOrderStatus2Shipping(orderCode);
        }
        if(ofcReceiveNum>0 && (ofcReceiveNum==ofcOperNum || (ofcReceiveNum+ofcCancleNum)==ofcOperNum ||
                (ofcReceiveNum+ofcRejectNum)==ofcOperNum || (ofcReceiveNum+ofcCancleNum+ofcRejectNum)==ofcOperNum)){
            //如果所有的都是已收货或除已收货的都是取消或拒收的，那么是已收货
            saveOrderStatus2SignIn(orderCode);
        }
        if(ofcRejectNum>0 &&  ofcCancleNum>0 && (ofcRejectNum+ofcCancleNum)==ofcOperNum){
            //如果所有的都是取消或拒收的，那么是已取消
            saveOrderStatus2Cancel(orderCode);
        }
        if(ofcCancleNum>0 && ofcCancleNum==ofcOperNum){
            //如果所有的都是取消的，那么是已取消
            saveOrderStatus2Cancel(orderCode);
        }
        if(ofcRejectNum>0 && ofcRejectNum==ofcOperNum){
            //如果所有的都是拒收的，那么是已拒收
            saveOrderStatus2Refund(orderCode);
        }
    }

    private String querySourceOrderCode(String orderCode) throws Exception{
        OfcIOrderRela orderRela = ofcIOrderRelaMapper.selectByOrderId(orderCode);
        if(null != orderRela && StringUtils.isNotBlank(orderRela.getParentOrder())){
            return orderRela.getParentOrder();
        }else{
            return null;
        }
    }

    @Transactional
    private void saveOrderStatus2WaitShipping(String orderCode){
        IOrder order = Optional.ofNullable(orderMapper.selectByOrderCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的订单不存在"));
        order.setLogisticsStatus(LogisticsStatus.NOT_SHIPPED.getValue());
        order.setAppStatus(orderStatusService.getAppStatus(order).getValue());
        orderMapper.updateByPrimaryKey(order);
    }


    @Override
    @Transactional
    public void updateOrderStatus2Split(String orderCode) throws Exception {
        IOrder order = Optional.ofNullable(orderMapper.selectByOrderCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的订单不存在"));
        order.setOrderStatus(OrderStatus.OFC_SPLIT_ORDER.getValue());
        order.setAppStatus(orderStatusService.getAppStatus(order).getValue());
        orderMapper.updateByPrimaryKey(order);
    }

    @Override
    @Transactional
    public void updateOrderStatus2Shipping(String orderCode) throws Exception {
        saveOrderStatus2Shipping(orderCode);
        String parentOrderCode = querySourceOrderCode(orderCode);
        if(StringUtils.isNotBlank(parentOrderCode)){
            decideAndChangeParentStatus(parentOrderCode);
        }
    }

    @Override
    @Transactional
    public void updateInvoiceOrderStatus2Shipping(String orderCode) throws Exception {
        IInvoice iInvoice = Optional.ofNullable(invoiceMapper.selectByInvoiceCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的发票订单不存在"));
        iInvoice.setStatus(InvoiceStatus.SENT.getValue());
        invoiceMapper.updateByPrimaryKey(iInvoice);

        IInvoiceLogistics invoiceLogistics = Optional.ofNullable(invoiceLogisticsMapper.selectByInvoiceId(iInvoice.getInvoiceId()))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的发票订单送货信息不存在"));
        invoiceLogistics.setSendDate(new Date());
        invoiceLogisticsMapper.updateByPrimaryKey(invoiceLogistics);

    }

    @Transactional
    private void saveOrderStatus2Shipping(String orderCode){
        IOrder order = Optional.ofNullable(orderMapper.selectByOrderCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的订单不存在"));
        order.setLogisticsStatus(LogisticsStatus.SHIPPED.getValue());
        order.setAppStatus(orderStatusService.getAppStatus(order).getValue());
        orderMapper.updateByPrimaryKey(order);

        IOrderLogistics orderLogistics = Optional.ofNullable(orderLogisticsMapper.selectByOrderId(order.getOrderId()))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的订单送货信息不存在"));
        orderLogistics.setSendDate(new Date());
        orderLogisticsMapper.updateByPrimaryKey(orderLogistics);
    }

    @Override
    @Transactional
    public void updateOrderStatus2Cancel(String orderCode) throws Exception {
        saveOrderStatus2Cancel(orderCode);
        String parentOrderCode = querySourceOrderCode(orderCode);
        if(StringUtils.isNotBlank(parentOrderCode)){
            decideAndChangeParentStatus(parentOrderCode);
        }
    }

    @Transactional
    private void saveOrderStatus2Cancel(String orderCode){
        IOrder order = Optional.ofNullable(orderMapper.selectByOrderCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的订单不存在"));
        order.setOrderStatus(OrderStatus.CANCELED.getValue());
        order.setLogisticsStatus(LogisticsStatus.CANCLE.getValue());
        order.setDelStatus(YesNo.YES.getValue());
        order.setCancelDate(new Date());
        order.setAppStatus(orderStatusService.getAppStatus(order).getValue());
        orderMapper.updateByPrimaryKey(order);
    }

    @Override
    @Transactional
    public void updateOrderStatus2Refund(String orderCode) throws Exception {
        saveOrderStatus2Refund(orderCode);
        String parentOrderCode = querySourceOrderCode(orderCode);
        if(StringUtils.isNotBlank(parentOrderCode)){
            decideAndChangeParentStatus(parentOrderCode);
        }
    }

    @Override
    public void updateInvoiceOrderStatus2Cancel(String orderCode) throws Exception {
        IInvoice iInvoice = Optional.ofNullable(invoiceMapper.selectByInvoiceCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的发票订单不存在"));
        iInvoice.setStatus(InvoiceStatus.CANCEL.getValue());
        invoiceMapper.updateByPrimaryKey(iInvoice);
    }

    @Override
    public void updateInvoiceOrderStatus2Refund(String orderCode) throws Exception {
        IInvoice iInvoice = Optional.ofNullable(invoiceMapper.selectByInvoiceCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的发票订单不存在"));
        iInvoice.setStatus(InvoiceStatus.CANCEL.getValue());
        invoiceMapper.updateByPrimaryKey(iInvoice);
    }

    @Transactional
    private void saveOrderStatus2Refund(String orderCode){
        IOrder order = Optional.ofNullable(orderMapper.selectByOrderCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的订单不存在"));
        order.setOrderStatus(OrderStatus.CANCELED.getValue());
        order.setLogisticsStatus(LogisticsStatus.CANCLE.getValue());
        order.setDelStatus(YesNo.YES.getValue());
        order.setCancelDate(new Date());
        order.setAppStatus(orderStatusService.getAppStatus(order).getValue());
        orderMapper.updateByPrimaryKey(order);
    }

    @Override
    @Transactional
    public void updateOrderStatus2SignIn(String orderCode) throws Exception {
        saveOrderStatus2SignIn(orderCode);
        String parentOrderCode = querySourceOrderCode(orderCode);
        if(StringUtils.isNotBlank(parentOrderCode)){
            decideAndChangeParentStatus(parentOrderCode);
        }
    }

    @Override
    @Transactional
    public void updateInvoiceOrderStatus2SignIn(String orderCode) throws Exception {
        IInvoice iInvoice = Optional.ofNullable(invoiceMapper.selectByInvoiceCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的发票订单不存在"));
        iInvoice.setStatus(InvoiceStatus.RECEIVE.getValue());
        invoiceMapper.updateByPrimaryKey(iInvoice);

        IInvoiceLogistics invoiceLogistics = Optional.ofNullable(invoiceLogisticsMapper.selectByInvoiceId(iInvoice.getInvoiceId()))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的发票订单送货信息不存在"));
        invoiceLogistics.setReceiveDate(new Date());
        invoiceLogisticsMapper.updateByPrimaryKey(invoiceLogistics);

    }

    @Transactional
    private void saveOrderStatus2SignIn(String orderCode){
        IOrder order = Optional.ofNullable(orderMapper.selectByOrderCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为：" + orderCode + "的订单不存在"));
        order.setLogisticsStatus(LogisticsStatus.RECEIVED.getValue());
        order.setAppStatus(orderStatusService.getAppStatus(order).getValue());
        orderMapper.updateByPrimaryKey(order);

        IOrderLogistics orderLogistics = Optional.ofNullable(orderLogisticsMapper.selectByOrderId(order.getOrderId()))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的订单送货信息不存在"));
        orderLogistics.setReceiveDate(new Date());
        orderLogisticsMapper.updateByPrimaryKey(orderLogistics);
    }

    @Override
    @Transactional
    public void addSkuStock(String orderCode) throws Exception {
        List<IOrderDetail> detailList = Optional.ofNullable(orderDetailMapper.selectByOrderCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, OfcConstants.ORDER_PROBLEM.PROBLEM_MESSAGE.ORDER_DETAIL_MISS));

        AddStockParamVo addStockParamVo = new AddStockParamVo();
        List<AddStockParamVo.GoodsNumVo> skus = new ArrayList<AddStockParamVo.GoodsNumVo>();
        addStockParamVo.setOrderCode(orderCode);
        addStockParamVo.setOfcOrderCode(orderCode);
        detailList.forEach(orderDetail -> {
            AddStockParamVo.GoodsNumVo goodsNumVo = new AddStockParamVo.GoodsNumVo();
            goodsNumVo.setSkuId(orderDetail.getSkuId());
            goodsNumVo.setNum(orderDetail.getNum());
            skus.add(goodsNumVo);
        });
        addStockParamVo.setSkus(skus);
        stockService.addStock(addStockParamVo);
    }

    @Override
    @Transactional
    public void addPoint(String orderCode) throws Exception {
        IOrder order = Optional.ofNullable(orderMapper.selectByOrderCode(orderCode))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单编码为："+orderCode+"的订单不存在"));
        OperationPointParameter addPointReqVo= new OperationPointParameter();
        addPointReqVo.setOfcOrderCode(orderCode);
        addPointReqVo.setOrderCode(orderCode);
        addPointReqVo.setPoint(order.getFee());
        addPointReqVo.setPointTradeType(PointTradeType.ADD);
        addPointReqVo.setUserId(order.getUserId());
        //获取订单支付信息
        IOrderPay iOrderPay = Optional.ofNullable(orderPayMapper.selectByOrderId(order.getOrderId()))
                .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单ID："+order.getOrderId()+"的订单支付信息不存在"));
        addPointReqVo.setOrganizationId(iOrderPay.getOrganizationId());
        if(iOrderPay.getPayer().equals(Payer.PERSONAL.getValue())){
            addPointReqVo.setPointType(PointType.PERSONAL);
        }else{
            addPointReqVo.setPointType(PointType.ORGANIZATION);
        }
        userPointService.operationPoint(addPointReqVo);
    }

    @Override
    public boolean sync2Ofc(Integer receiveOrderNum) throws Exception {
        operateSalesOrder(receiveOrderNum);
        operateInvoiceOrder(receiveOrderNum);
        return true;
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    private void operateInvoiceOrder(Integer receiveOrderNum) throws Exception{
        List<IInvoice> invoices = invoiceMapper.selectInvoiceForOfc(receiveOrderNum);
        if(CollectionUtils.isNotEmpty(invoices)){
            List<String> invoiceCodes = new ArrayList<>();
            List<OfcIOrderInfo> ofcIOrderInfos = new ArrayList<>();
            invoices.forEach(invoice -> {
                invoice.setOfcStatus(YesNo.YES.getValue());
                ofcIOrderInfos.add(constructOfcOrder4InvoiceOrder(invoice));
                invoiceCodes.add(invoice.getInvoiceCode());
            });
            invoiceMapper.batchUpdate(invoices);
            //修改订单ofc状态信息
            ofcIOrderInfoMapper.batchInsertOrders(ofcIOrderInfos);
            //保存ofc日志记录
            orderLogService.batchSaveOrderTraceingInfo(invoiceCodes, OfcOrderStatus.WAIT_SHIPPING.getValue(), OfcConstants.SYSTEM_OPERATOR.NAME, OfcOrderStatus.WAIT_SHIPPING.getName());
            orderLogService.batchSaveSysLog(null, invoiceCodes, OfcConstants.SYSTEM_LOG_MESSAGE.WAIT_SHIPPING, null, YesNoBoolean.NO.getValue());
        }
    }

    private OfcIOrderInfo constructOfcOrder4InvoiceOrder(IInvoice invoice){
        OfcIOrderInfo orderInfo = new OfcIOrderInfo();

        //订单基本信息
        orderInfo.setOrderId(invoice.getInvoiceCode());
        orderInfo.setUserId(invoice.getUserId().toString());
        orderInfo.setOrderEntranceId(ORDER_ENTRANCE_ID);
        orderInfo.setUserRemark(StringUtils.isNotBlank(invoice.getRemark())?invoice.getRemark():"");
        orderInfo.setOrderTime(invoice.getOpdate());
        orderInfo.setOrderType(OfcOrderType.INVOICE_ORDER.getValue());
        orderInfo.setOrderTerms(1);
        orderInfo.setOrderStatus(OfcOrderStatus.WAIT_SHIPPING.getValue());
        orderInfo.setOrderCancelStatus(YesNoBoolean.NO.getValue());
        //订单审核类信息
        orderInfo.setAuditTimes(0);
        //订单时间类型信息
        orderInfo.setCreatedAt(new Date());
        orderInfo.setOfcReceivedAt(new Date());
        //订单状态判断类信息
        orderInfo.setIsDeleted(YesNoBoolean.NO.getValue());
        orderInfo.setIsBlocked(YesNoBoolean.NO.getValue());
        orderInfo.setIsProblemOrder(YesNoBoolean.NO.getValue());
        orderInfo.setIsFreightCollect(YesNoBoolean.NO.getValue());
        orderInfo.setIsLock(YesNoBoolean.NO.getValue());
        orderInfo.setIsManualPause(YesNoBoolean.NO.getValue());
        orderInfo.setIsPause(YesNoBoolean.NO.getValue());
        orderInfo.setIsUrgent(YesNoBoolean.NO.getValue());
        return orderInfo;
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    private void operateSalesOrder(Integer receiveOrderNum) throws Exception{
        List<IOrder> orderList = orderMapper.selectOrderForOfc(receiveOrderNum);
        if( CollectionUtils.isNotEmpty(orderList)){
            List<String> orderCodes = new ArrayList<String>();
            List<OfcIOrderInfo> ofcIOrderInfos = new ArrayList<OfcIOrderInfo>();
            orderList.forEach(order -> {
                order.setOfcStatus(YesNo.YES.getValue());
                //获取订单支付信息
                IOrderPay iOrderPay = Optional.ofNullable(orderPayMapper.selectByOrderId(order.getOrderId()))
                        .orElseThrow(() -> new RetException(ReturnCodeConstants.INVALID_PARAMETER_CODE, "订单ID："+order.getOrderId()+"的订单支付信息不存在"));
                //获取订单留言信息
                IOrderRemark orderRemark = orderRemarkMapper.selectByOrderId(order.getOrderId());
                OfcIOrderInfo orderInfo = constructOfcOrder4SalesOrder(order, iOrderPay, orderRemark);
                ofcIOrderInfos.add(orderInfo);
                orderCodes.add(order.getOrderCode());
            });
            orderMapper.batchUpdateOrders(orderList);
            //修改订单ofc状态信息
            ofcIOrderInfoMapper.batchInsertOrders(ofcIOrderInfos);
            //保存ofc日志记录
            orderLogService.batchSaveOrderTraceingInfo(orderCodes, OfcOrderStatus.OFC_ORDER_INIT.getValue(), OfcConstants.SYSTEM_OPERATOR.NAME, OfcOrderStatus.OFC_ORDER_INIT.getName());
            orderLogService.batchSaveSysLog(null, orderCodes, OfcConstants.SYSTEM_LOG_MESSAGE.INIT_ORDER, null, YesNoBoolean.NO.getValue());
        }
    }

    private OfcIOrderInfo constructOfcOrder4SalesOrder(IOrder order, IOrderPay iOrderPay, IOrderRemark orderRemark){
        OfcIOrderInfo orderInfo = new OfcIOrderInfo();

        //订单基本信息
        orderInfo.setOrderId(order.getOrderCode());
        orderInfo.setUserId(order.getUserId().toString());
        orderInfo.setOrderEntranceId(ORDER_ENTRANCE_ID);
        orderInfo.setUserRemark(null!=orderRemark?orderRemark.getBuyerRemark():"");
        orderInfo.setPaymentMethod(iOrderPay.getPayer().toString());
        orderInfo.setPaymentStatus(order.getPayStatus() == null ? 0 : order.getPayStatus());
        orderInfo.setPaymentType(iOrderPay.getPaywayId());
        orderInfo.setPaymentTime(iOrderPay.getPayDate());
        orderInfo.setOrderTime(order.getOpdate());
        orderInfo.setOrderType(OfcOrderType.SALES_ORDER.getValue());
        orderInfo.setOrderTerms(1);
        orderInfo.setOrderStatus(OfcOrderStatus.OFC_ORDER_INIT.getValue());
        orderInfo.setOrderCancelStatus(YesNoBoolean.NO.getValue());
        //订单审核类信息
        orderInfo.setAuditTimes(0);
        //订单时间类型信息
        orderInfo.setCreatedAt(new Date());
        orderInfo.setOfcReceivedAt(new Date());
        //订单状态判断类信息
        orderInfo.setIsDeleted(YesNoBoolean.NO.getValue());
        orderInfo.setIsBlocked(YesNoBoolean.NO.getValue());
        orderInfo.setIsProblemOrder(YesNoBoolean.NO.getValue());
        orderInfo.setIsFreightCollect(YesNoBoolean.NO.getValue());
        orderInfo.setIsLock(YesNoBoolean.NO.getValue());
        orderInfo.setIsManualPause(YesNoBoolean.NO.getValue());
        orderInfo.setIsPause(YesNoBoolean.NO.getValue());
        orderInfo.setIsUrgent(YesNoBoolean.NO.getValue());
        return orderInfo;
    }

}
